package com.mystudy.concurrent.threadLocal;

import java.util.Random;

/**
 * TODO:
 *
 * @author acy
 * @since 2019/05/29 18:35
 */
public class ThreadLocakComplexTest {
	private static final ThreadLocal<String> THREAD_LOCAL=new ThreadLocal<>();

	private static final Random RANDOM=new Random(System.currentTimeMillis());
	public static void main(String[] args) {
		Thread thread = new Thread(() -> {
			THREAD_LOCAL.set("Thread-1");
			try {
				Thread.sleep(1000);
				System.out.println(Thread.currentThread().getName() + "------" + THREAD_LOCAL.get());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

		Thread thread2 = new Thread(() -> {
			THREAD_LOCAL.set("Thread-2");
			try {
				Thread.sleep(1000);
				System.out.println(Thread.currentThread().getName() + "------" + THREAD_LOCAL.get());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

		thread.start();
		thread2.start();
		try {
			thread.join();
			thread2.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("-------");
		System.out.println(Thread.currentThread().getName() + "------" + THREAD_LOCAL.get());

	}
}
